import os
import glob
import pandas as pd
import numpy as np

def csv_to_npy(csv_path, npy_path):
    # 读取CSV文件
    data = pd.read_csv(csv_path)
    # 将数据保存为NPy文件
    np.save(npy_path, data.values)

def convert_all_csv_to_npy(input_directory, output_directory):
    # 找到目录下的所有CSV文件
    csv_files = glob.glob(os.path.join(input_directory, '*.csv'))
    # 将每个CSV文件转换为NPy文件
    for csv_file in csv_files:
        # 创建NPy文件的路径
        base_name = os.path.basename(csv_file)
        npy_file = os.path.join(output_directory, os.path.splitext(base_name)[0] + '.npy')
        # 转换文件
        csv_to_npy(csv_file, npy_file)

# 使用示例
convert_all_csv_to_npy('E:/pythonProject/粒子滤波/ADS-B/筛选航迹', 'E:/pythonProject/粒子滤波/ADS-B/筛选航迹-npy')